package com.jxk.security.controller;


import com.jxk.security.entity.User;
import com.jxk.security.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.annotation.Secured;
import org.springframework.security.crypto.password.PasswordEncoder;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;

import org.springframework.web.bind.annotation.RestController;

/**
 * <p>
 *  前端控制器
 * </p>
 *
 * @author jxk
 * @since 2020-10-25
 */
@RestController
@RequestMapping("/user")
public class UserController {
    @Autowired
    private PasswordEncoder passwordEncoder;
    @Autowired
    protected UserService userService;
    @Secured(value = "ROLE_董事长")
    @GetMapping("/hello")
    public String Hello(){
        return  "hello";
    }
    @GetMapping("/lala")
    public  String lala(){
        return  "lala";
    }
    @GetMapping("addUser")
    public String addUser(String name,String password){
        User user = new User( name, passwordEncoder.encode(password));
        userService.save(user);
        return "success";
    }
}

